import { wxShare } from "@/utils";
import uuidv1 from "uuid/v1";
import { gbs } from "@/config/index";
import lifeData from "@/db/life"
import commonFn from "@/utils/commonFn/index"
import html2canvas from "html2canvas"
export default {
  name: "",
  data() {
    return {
      req: {},
      
      login: false,
      lifeData: [],
      allTime: '',
      userName: '',
      imgAddr: '',
      show: true
    };
  },
  methods: {
    getLocal(){
      let list = JSON.parse(window.localStorage.getItem('topicList'))
      this.lifeData = list.filter(item => {
        if(item.think_do || item.done_do) return item
      })
      this.allTime = commonFn.formatTime(new Date())
      this.$nextTick(res => {
        setTimeout(() => {
          this.loadImg()
          const linepo = document.getElementById('footer').offsetTop
          document.querySelector('.center-tips').style.top = linepo - 20  + 'px'
          document.querySelector('.center-tips').style.backgroundColor = '#434343'
        }, 800) 
        
        
    })
    if(localStorage.getItem("user")) {
      this.userName = JSON.parse(localStorage.getItem("user")).nickname
    }
      
    },
    loadImg(){
      const dom = document.getElementById("html-img");
      html2canvas(dom, {
          useCORS: true,
          allowTaint: false,
          // width: dom.offsetWidth * 2,
          // height: dom.offsetHeight * 2
      }).then(canvas => {
          this.imgAddr = canvas.toDataURL("image/jpeg");
          this.show = false
          setTimeout(() => { this.$vux.loading.hide(); }, 1000)
      });

    },
    share () {
      wxShare({
        title: "人生清单",
        text: "这66件事，只要完成其中10件，人生就会很圆满。",
        href: "http://app.allclinic.cn/h5/wx/startActivity/#/life/index",
        imgUrl: "http://app.allclinic.cn/h5/wx/scan_drug/static/img/logo.jpg",
        appMessageSuccFn: () => {
          this.shareHandle()
        },
        timeLineSuccFn: () => {
          this.shareHandle()
        }
      });
    }
  },
  mounted() {
    this.share()
    this.$vux.loading.show({
        text: "数据生成..."
    });
    this.getLocal()
    
  }
};